package itheima.zuiye.Test.Test0;

public class MyRunnable  implements Runnable{
    int num =100;
    @Override
    public void run() {
        while (true){
            if(sendGift()){
                break;
            }
        }

    }
    private  synchronized boolean sendGift(){
        if( num >10){
            System.out.println(Thread.currentThread().getName()+"正在发送第"+num+"个礼物...");
            num--;
            try{
                Thread.sleep(300);
            }catch (InterruptedException e){
                throw new RuntimeException(e);
            }
            return false;
        }else {
            System.out.println(Thread.currentThread().getName()+"送完了所有礼物！");
            return true;


        }
    }
}
